package thinkinjava4.ch22_gui;

import thinkinjava4.util.Generator;
import thinkinjava4.util.RandomGenerator;

import javax.swing.*;
import java.awt.*;

public class TextPane extends JFrame {
    private JButton b = new JButton("Add Text");
    private JTextPane tp = new JTextPane();
    private static Generator sg = new RandomGenerator.String(7);

    public TextPane() {
        b.addActionListener(event -> {
            for (int i = 1; i < 10; i++)
                tp.setText(tp.getText() + sg.next() + "\n");
        });
        add(new JScrollPane(tp));
        add(BorderLayout.SOUTH, b);
    }

    public static void main(String[] args) {
        SwingConsole.run(new TextPane(), 475, 425);
    }
}
